package com.sc.nft.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.dao.SpecialEventManagementBindingDao;
import com.sc.nft.entity.SpecialEventManagementBinding;
import com.sc.nft.entity.dto.SpecialEventManagementBindingEditDTO;
import com.sc.nft.entity.dto.SpecialEventManagementBindingSaveDTO;
import com.sc.nft.entity.vo.SpecialEventManagementBindingVO;
import com.sc.nft.exception.GlobalRunTimeException;
import com.sc.nft.service.SpecialEventManagementBindingService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 专场管理(SpecialEventManagementBinding)表服务实现类
 *
 * @author 王伟成
 * @since 2023-10-10 15:25:10
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class SpecialEventManagementBindingServiceImpl implements SpecialEventManagementBindingService {

    private final SpecialEventManagementBindingDao specialEventManagementBindingDao;
    @Override
    public void save(SpecialEventManagementBindingSaveDTO specialEventManagementBindingSaveDTO) {
        // 过滤重复选中的内容  需要过滤已经添加到其他专场的商品
        if (specialEventManagementBindingDao.isBinding(specialEventManagementBindingSaveDTO.getCollectionId())){
            throw new GlobalRunTimeException("该藏品已经绑定其他专场");
        }
        // 保存
        SpecialEventManagementBinding specialEventManagementBinding = BeanUtil.copyProperties(specialEventManagementBindingSaveDTO, SpecialEventManagementBinding.class);
        specialEventManagementBinding.setEventManagementId(specialEventManagementBindingSaveDTO.getSpecialEventId());
        specialEventManagementBinding.insert();
    }
    @Override
    public void edit(SpecialEventManagementBindingEditDTO specialEventManagementBindingEditDTO) {
        BeanUtil.copyProperties(specialEventManagementBindingEditDTO, SpecialEventManagementBinding.class).updateById();
    }
    @Override
    public void removeById(Long id) {
        specialEventManagementBindingDao.removeById(id);
    }
    @Override
    public List<SpecialEventManagementBindingVO> list(Long id) {
        return specialEventManagementBindingDao.listLeftJoinDig(id);
    }


}
